import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * This class contains the main operations of the circuits.
 * 
 * @author Christian Pérez Zavalija
 * @version 25-Jun-2013
 */
public class Circuit extends Actor
{
    protected Pin[] pins;
    private int band;
    
    /**
     * Pin arrangement adds to the world with their respective distance between them and the width of
     * the circuit.
     */
    public void addedToWorld(World world)
    {
        int y=getY()+28;
        int x=getX()-42;
        for(int i=0;i<14;i++){
            if(i==7){
                y-=55;
                x=x-(14*i);
            }
            getWorld().addObject(pins[i],x,y);
            x+=14;
        }
    }
    
    /**
     * This constructor creates the necessary pins to the circuit and puts them into an array.
     */
    public Circuit()
    {
        pins=new Pin[14];
        for(int i=0;i<14;i++){
            Pin pin=new Pin(10);
            pins[i]=pin;
        }
    }
    
    /**
     * This method calls the method scale() of its subclass.
     */
    public void scale()
    {    }
    
    /**
     * If you touch one of the pins with the dump, the pins are removed.
     */
    public void eliminate()
    {
        removeTouching(Pin.class);
    }
    
    /**
     * Permit drag each circuit with their respective pins.
     */
    public void act() 
    {
        if(Greenfoot.mouseDragged(this))    //Condition so that the object can be dragged with the mouse while pressing the left button.
        {
            MouseInfo mouse=Greenfoot.getMouseInfo();
            setLocation(mouse.getX(),mouse.getY());
            int y=getY()+28;
            int x=getX()-42;
            for(int i=0;i<14;i++){
                if(i==7){
                    y-=55;
                    x=x-(14*i);
                }
                pins[i].setLocation(x,y);
                x+=14;
            }
        }
    }    
}
